import { createApp } from 'vue';
import Popup from './index.vue';
// import store from '@/store';

let RuleVue;

// 创建挂载实例
let createRulePopup = (opts) => {
  const mountNode = document.createElement('div');
  document.body.appendChild(mountNode);

  const app = createApp(Popup, {
    ...opts,
    modelValue: true,
    remove() {
      app.unmount(mountNode);
      document.body.removeChild(mountNode);
    }
  });
  return app.mount(mountNode);
};
export function showPopup(args, callback) {
  // 为了让当前的实例 只有一个，防止占用太多内存
  if (!RuleVue) {
    RuleVue = createRulePopup();
  }
  RuleVue.showBox(args);
  callback && callback();
  return RuleVue;
}
